
Create table [purchases_orders_labeled_distributions]
(
	[purchase_order_labeled_distribution_id] Bigint Identity NOT NULL,
	[purchase_order_version_id] Integer NOT NULL,
	[plant_version_id] Integer NOT NULL,
	[quantity] Decimal(18,4) NOT NULL,
Primary Key ([purchase_order_labeled_distribution_id])
) 
go

Create UNIQUE Index [IX_pold_purchase_order_version_id_plant_version_id] ON [purchases_orders_labeled_distributions] ([purchase_order_version_id] ,[plant_version_id] ) 
go
Create Index [IX_pold_purchase_order_version_id] ON [purchases_orders_labeled_distributions] ([purchase_order_version_id] ) 
go
Create Index [IX_pold_plant_version_id] ON [purchases_orders_labeled_distributions] ([plant_version_id] ) 
go

Alter table [purchases_orders_labeled_distributions] add  foreign key([purchase_order_version_id]) references [purchases_orders_versions] ([purchase_order_version_id])  on update no action on delete cascade 
go
Alter table [purchases_orders_labeled_distributions] add  foreign key([plant_version_id]) references [plants_versions] ([plant_version_id])  on update no action on delete cascade 
go
